package com.example.bio;

import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.*;

/**
 * @Description
 * @Author 26233
 * @Create 2021-10-27 16:09:13
 */

public class NormalServer {

    public static void main(String[] args) throws IOException {

        String hostName = "192.168.101.8";
        int port = 8888;
        ServerSocket serverSocket = new ServerSocket();
        serverSocket.bind(new InetSocketAddress(hostName, port));
        System.out.println("echo start...");

        Socket clientSocket;
        try {
            while ((clientSocket = serverSocket.accept()) != null){
                InputStream inputStream = clientSocket.getInputStream();
                OutputStream outputStream = clientSocket.getOutputStream();

                inputStream.available();

                byte[] recv = new byte[1024];
                int read = inputStream.read(recv);
                System.out.println("read = " + read);

                outputStream.write("ok".getBytes());
                System.out.println("ok");
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            serverSocket.close();
        }

    }

}
